<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>更改用户</title>
	<link rel="stylesheet" href="/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
	<style>
		input.error{
			border: 1px solid #E6594E;
		}
	</style>
</head>
<body>
    <div class="container">
	
		<form id="editUserForm">
		  <br/>
		  <div class="form-group">
			<label for="username">用户名称:</label>
			<input type="text" class="form-control" id="username" name="username" value="${data.name}" placeholder="用户名">
		  </div>
		  <div class="form-group">
			<label for="userpassword">用户密码:</label>
			<input type="password" class="form-control" id="userpassword" name="userpassword" value="${data.password}" placeholder="密码">
		  </div>
		  <div class="form-group">
			<label for="usersex">性别</label>
			<input type="text" class="form-control" id="usersex" name="usersex" value="${data.sex}" placeholder="性别">
		  </div>
		  <div class="form-group">
			<label for="userphone">用户联系方式</label>
			<input type="text" class="form-control" id="userphone" name="userphone" value="${data.phone}" placeholder="联系方式">
		  </div>
		  <div class="form-group">
		  <button type="button" id="saveBtn" class="btn btn-success">提交</button>
		  <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
		  </div>
		</form>
    </div>

		<script>
			var editUser = function(){
				if(!check().form()){ 
					return;
				}
				alert(123)
				$.ajax({
					   type: "GET",
					   dataType: "json",
					   url: "/user/edit",
					   data: {
							"id": ${data.id},
							"name": $("#username").val(),
							"password":$("#userpassword").val(),
							"sex":$("#usersex").val(),
							"phone":$("#userphone").val()
					   },
					   success: function(msg){
							$('#cancelBtn').click();			
					   }
				});
			}
			
			$('#saveBtn').on('click', function(){
				editUser();
			});
			
			$('#cancelBtn').on('click', function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.getUserPageList();
				parent.layer.close(index);
			});

			//校验字段是否正确  
            function check(){ 
                 /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
                return $("#editUserForm").validate({ 
                            rules:{ 
                                username:{ 
                                    required:true
                                },
                                userage:{ 
                                    required:true                                   
                                }
                            }, 
                            messages:{ 
                                username:{ 
                                    required:""
                                },
                                userage:{ 
                                    required:""                                
                                }
                            }     
                        }); 
            } 
			
		</script> 	
</body>
</html>